package org.xtext.example.mydsl.serializer;

import com.google.inject.Inject;
import com.google.inject.Provider;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.serializer.acceptor.ISemanticSequenceAcceptor;
import org.eclipse.xtext.serializer.acceptor.SequenceFeeder;
import org.eclipse.xtext.serializer.diagnostic.ISemanticSequencerDiagnosticProvider;
import org.eclipse.xtext.serializer.diagnostic.ISerializationDiagnostic.Acceptor;
import org.eclipse.xtext.serializer.sequencer.AbstractSemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.GenericSequencer;
import org.eclipse.xtext.serializer.sequencer.ISemanticNodeProvider.INodesForEObjectProvider;
import org.eclipse.xtext.serializer.sequencer.ISemanticSequencer;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService;
import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient;
import org.xtext.example.mydsl.myDsl.Abs;
import org.xtext.example.mydsl.myDsl.App;
import org.xtext.example.mydsl.myDsl.Dich;
import org.xtext.example.mydsl.myDsl.Import;
import org.xtext.example.mydsl.myDsl.Let;
import org.xtext.example.mydsl.myDsl.MyDslPackage;
import org.xtext.example.mydsl.myDsl.Nrif;
import org.xtext.example.mydsl.myDsl.Prog;
import org.xtext.example.mydsl.myDsl.T1;
import org.xtext.example.mydsl.myDsl.T2;
import org.xtext.example.mydsl.myDsl.T3;
import org.xtext.example.mydsl.myDsl.Tapp;
import org.xtext.example.mydsl.myDsl.Trif;
import org.xtext.example.mydsl.myDsl.TypeDich;
import org.xtext.example.mydsl.myDsl.Uq;
import org.xtext.example.mydsl.myDsl.Var;
import org.xtext.example.mydsl.services.MyDslGrammarAccess;

@SuppressWarnings("restriction")
public class AbstractMyDslSemanticSequencer extends AbstractSemanticSequencer {

	@Inject
	protected MyDslGrammarAccess grammarAccess;
	
	@Inject
	protected ISemanticSequencerDiagnosticProvider diagnosticProvider;
	
	@Inject
	protected ITransientValueService transientValues;
	
	@Inject
	@GenericSequencer
	protected Provider<ISemanticSequencer> genericSequencerProvider;
	
	protected ISemanticSequencer genericSequencer;
	
	
	@Override
	public void init(ISemanticSequencer sequencer, ISemanticSequenceAcceptor sequenceAcceptor, Acceptor errorAcceptor) {
		super.init(sequencer, sequenceAcceptor, errorAcceptor);
		this.genericSequencer = genericSequencerProvider.get();
		this.genericSequencer.init(sequencer, sequenceAcceptor, errorAcceptor);
	}
	
	public void createSequence(EObject context, EObject semanticObject) {
		if(semanticObject.eClass().getEPackage() == MyDslPackage.eINSTANCE) switch(semanticObject.eClass().getClassifierID()) {
			case MyDslPackage.ABS:
				if(context == grammarAccess.getAbsRule() ||
				   context == grammarAccess.getTermRule()) {
					sequence_Abs(context, (Abs) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.APP:
				if(context == grammarAccess.getAppRule() ||
				   context == grammarAccess.getTermRule()) {
					sequence_App(context, (App) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.DICH:
				if(context == grammarAccess.getDichRule()) {
					sequence_Dich(context, (Dich) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.IMPORT:
				if(context == grammarAccess.getImportRule()) {
					sequence_Import(context, (Import) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.LET:
				if(context == grammarAccess.getLetRule() ||
				   context == grammarAccess.getTermRule()) {
					sequence_Let(context, (Let) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.NRIF:
				if(context == grammarAccess.getNrifRule() ||
				   context == grammarAccess.getTermRule()) {
					sequence_Nrif(context, (Nrif) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.PROG:
				if(context == grammarAccess.getProgRule()) {
					sequence_Prog(context, (Prog) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.T1:
				if(context == grammarAccess.getTRule() ||
				   context == grammarAccess.getT1Rule()) {
					sequence_T1(context, (T1) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.T2:
				if(context == grammarAccess.getTRule() ||
				   context == grammarAccess.getT2Rule()) {
					sequence_T2(context, (T2) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.T3:
				if(context == grammarAccess.getTRule() ||
				   context == grammarAccess.getT3Rule()) {
					sequence_T3(context, (T3) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.TAPP:
				if(context == grammarAccess.getTappRule() ||
				   context == grammarAccess.getTermRule()) {
					sequence_Tapp(context, (Tapp) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.TRIF:
				if(context == grammarAccess.getTRule() ||
				   context == grammarAccess.getTrifRule()) {
					sequence_Trif(context, (Trif) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.TYPE_DICH:
				if(context == grammarAccess.getTypeDichRule()) {
					sequence_TypeDich(context, (TypeDich) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.UQ:
				if(context == grammarAccess.getTermRule() ||
				   context == grammarAccess.getUqRule()) {
					sequence_Uq(context, (Uq) semanticObject); 
					return; 
				}
				else break;
			case MyDslPackage.VAR:
				if(context == grammarAccess.getTermRule() ||
				   context == grammarAccess.getVarRule()) {
					sequence_Var(context, (Var) semanticObject); 
					return; 
				}
				else break;
			}
		if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
	}
	
	/**
	 * Constraint:
	 *     (param=variable type=T body=Term)
	 *
	 * Features:
	 *    param[1, 1]
	 *    type[1, 1]
	 *    body[1, 1]
	 */
	protected void sequence_Abs(EObject context, Abs semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.ABS__PARAM) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.ABS__PARAM));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.ABS__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.ABS__TYPE));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.ABS__BODY) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.ABS__BODY));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getAbsAccess().getParamVariableTerminalRuleCall_1_0(), semanticObject.getParam());
		feeder.accept(grammarAccess.getAbsAccess().getTypeTParserRuleCall_3_0(), semanticObject.getType());
		feeder.accept(grammarAccess.getAbsAccess().getBodyTermParserRuleCall_5_0(), semanticObject.getBody());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (t1=Term t2=Term)
	 *
	 * Features:
	 *    t1[1, 1]
	 *    t2[1, 1]
	 */
	protected void sequence_App(EObject context, App semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.APP__T1) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.APP__T1));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.APP__T2) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.APP__T2));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getAppAccess().getT1TermParserRuleCall_1_0(), semanticObject.getT1());
		feeder.accept(grammarAccess.getAppAccess().getT2TermParserRuleCall_3_0(), semanticObject.getT2());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID term=Term)
	 *
	 * Features:
	 *    name[1, 1]
	 *    term[1, 1]
	 */
	protected void sequence_Dich(EObject context, Dich semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.DICH__NAME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.DICH__NAME));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.DICH__TERM) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.DICH__TERM));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getDichAccess().getNameIDTerminalRuleCall_0_0(), semanticObject.getName());
		feeder.accept(grammarAccess.getDichAccess().getTermTermParserRuleCall_2_0(), semanticObject.getTerm());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     importURI=STRING
	 *
	 * Features:
	 *    importURI[1, 1]
	 */
	protected void sequence_Import(EObject context, Import semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.IMPORT__IMPORT_URI) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.IMPORT__IMPORT_URI));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getImportAccess().getImportURISTRINGTerminalRuleCall_1_0(), semanticObject.getImportURI());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (var=variable type=T t1=Term t2=Term)
	 *
	 * Features:
	 *    var[1, 1]
	 *    type[1, 1]
	 *    t1[1, 1]
	 *    t2[1, 1]
	 */
	protected void sequence_Let(EObject context, Let semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.LET__VAR) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.LET__VAR));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.LET__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.LET__TYPE));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.LET__T1) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.LET__T1));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.LET__T2) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.LET__T2));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getLetAccess().getVarVariableTerminalRuleCall_1_0(), semanticObject.getVar());
		feeder.accept(grammarAccess.getLetAccess().getTypeTParserRuleCall_3_0(), semanticObject.getType());
		feeder.accept(grammarAccess.getLetAccess().getT1TermParserRuleCall_5_0(), semanticObject.getT1());
		feeder.accept(grammarAccess.getLetAccess().getT2TermParserRuleCall_7_0(), semanticObject.getT2());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     nome=[Dich|ID]
	 *
	 * Features:
	 *    nome[1, 1]
	 */
	protected void sequence_Nrif(EObject context, Nrif semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.NRIF__NOME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.NRIF__NOME));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getNrifAccess().getNomeDichIDTerminalRuleCall_0_1(), semanticObject.getNome());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (importList+=Import? td+=TypeDich* d+=Dich* main=Term)
	 *
	 * Features:
	 *    importList[0, 1]
	 *    td[0, *]
	 *    d[0, *]
	 *    main[1, 1]
	 */
	protected void sequence_Prog(EObject context, Prog semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (p=tvar c+=T*)
	 *
	 * Features:
	 *    p[1, 1]
	 *    c[0, *]
	 */
	protected void sequence_T1(EObject context, T1 semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (p1=T c1+=T*)
	 *
	 * Features:
	 *    p1[1, 1]
	 *    c1[0, *]
	 */
	protected void sequence_T2(EObject context, T2 semanticObject) {
		genericSequencer.createSequence(context, semanticObject);
	}
	
	
	/**
	 * Constraint:
	 *     (var=tvar t=T)
	 *
	 * Features:
	 *    var[1, 1]
	 *    t[1, 1]
	 */
	protected void sequence_T3(EObject context, T3 semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.T3__VAR) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.T3__VAR));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.T3__T) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.T3__T));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getT3Access().getVarTvarTerminalRuleCall_1_0(), semanticObject.getVar());
		feeder.accept(grammarAccess.getT3Access().getTTParserRuleCall_2_0(), semanticObject.getT());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (term=Term type=T)
	 *
	 * Features:
	 *    term[1, 1]
	 *    type[1, 1]
	 */
	protected void sequence_Tapp(EObject context, Tapp semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.TAPP__TERM) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.TAPP__TERM));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.TAPP__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.TAPP__TYPE));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getTappAccess().getTermTermParserRuleCall_1_0(), semanticObject.getTerm());
		feeder.accept(grammarAccess.getTappAccess().getTypeTParserRuleCall_3_0(), semanticObject.getType());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     nome=[TypeDich|ID]
	 *
	 * Features:
	 *    nome[1, 1]
	 */
	protected void sequence_Trif(EObject context, Trif semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.TRIF__NOME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.TRIF__NOME));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getTrifAccess().getNomeTypeDichIDTerminalRuleCall_0_1(), semanticObject.getNome());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (name=ID type=T)
	 *
	 * Features:
	 *    name[1, 1]
	 *    type[1, 1]
	 */
	protected void sequence_TypeDich(EObject context, TypeDich semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.TYPE_DICH__NAME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.TYPE_DICH__NAME));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.TYPE_DICH__TYPE) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.TYPE_DICH__TYPE));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getTypeDichAccess().getNameIDTerminalRuleCall_0_0(), semanticObject.getName());
		feeder.accept(grammarAccess.getTypeDichAccess().getTypeTParserRuleCall_2_0(), semanticObject.getType());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     (var=tvar term=Term)
	 *
	 * Features:
	 *    var[1, 1]
	 *    term[1, 1]
	 */
	protected void sequence_Uq(EObject context, Uq semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.UQ__VAR) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.UQ__VAR));
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.UQ__TERM) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.UQ__TERM));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getUqAccess().getVarTvarTerminalRuleCall_1_0(), semanticObject.getVar());
		feeder.accept(grammarAccess.getUqAccess().getTermTermParserRuleCall_3_0(), semanticObject.getTerm());
		feeder.finish();
	}
	
	
	/**
	 * Constraint:
	 *     name=variable
	 *
	 * Features:
	 *    name[1, 1]
	 */
	protected void sequence_Var(EObject context, Var semanticObject) {
		if(errorAcceptor != null) {
			if(transientValues.isValueTransient(semanticObject, MyDslPackage.Literals.VAR__NAME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, MyDslPackage.Literals.VAR__NAME));
		}
		INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
		SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
		feeder.accept(grammarAccess.getVarAccess().getNameVariableTerminalRuleCall_0(), semanticObject.getName());
		feeder.finish();
	}
}
